<template>
	<view class="Select-merchant">
		<view class="merchantBox">
			<view class="merchant_top">
				<view class="searchBox">
					<u-search placeholder="搜索商户" v-model="keyword" :show-action="false"  @search="searchBtn"></u-search>
				</view>
				<!-- <view class="Navigation">
					<view class="NavigationItem" :class="{currentColor:current==index}" v-for="(item,index) in NavItem" @click="selectItem(index)">{{item.name}}</view>
				</view> -->
			</view>
			<view class="merchantList">
				<view class="ProductItem" v-for="(item,index) in list" :key="index" @click="selectStore" :data-index="index">
					<view class="ItemTop">
						<view class="ProductImage" :style="{'background-image':'url('+getImage(item.image_url)+')'}">
							<!-- <image :src="getImage(item.image_url)" mode=""></image> -->
						</view>
						<view class="ProductInfo">
							<view class="ProductNameBox">
								<view class="ProductName">{{item.name}}</view>
								<view class="sales-volume">售{{item.sales_volume_sum}}</view>
							</view>
							<view class="addressBox">
								<view class="address">{{item.industry.name}}</view>
								<view class="addressNum">{{item.distance}}km</view>
							</view>
							
						</view>
					</view>
					<!-- <view class="ItemBottom">
						<view class="couponBox" v-for="(item,index) in 3">
							<view class="couponIcon">惠</view>
							<view class="couponPrice">23.8元</view>
							<view class="coupontext">三件套单人套餐</view>
						</view>
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				NavItem:[{name:"收藏"},{name:"最近浏览"}],
				current:0,
				keyword:"",
				page:1,
				list:[],
				moreFlag:false,
				id:""
			}
		},
		onLoad(options) {
			
			this.getList();
		},
    onShow(){
      // #ifdef APP-PLUS
      var args = plus.runtime.arguments;
      if(args){
        app.$vm.setShareDetail(args);
      }
      // #endif
    },
		onReachBottom() {
			if(!this.moreFlag){
				return false;
			}
			this.moreFlag = false;
			this.page = this.page + 1;
			this.getList();
		},
		methods: {
			selectStore(e){
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				let page = getCurrentPages();
				page[page.length-2].$vm.storeData = this.list[index];
				uni.navigateBack({
					delta:1
				})
			},
			getImage(url){
				if(url&&(url.indexOf("http://")!=-1||url.indexOf("https://")!=-1)){
					return url;
				}else{
					return app.$vm.globalData.imgBaseUrl + url;
				}
			},
			getList(){
				let obj = {};
				// obj.page = this.page;
				if(this.keyword.trim()){
					obj.search = this.keyword;
				}
				let newObj = {};
				newObj.page = this.page;
				newObj.data = obj;
				this.$u.api.shopList(newObj).then(res=>{
					console.log(res)
					if(this.page == 1){
						this.list = res.data.list.data.map(cur=>{
							cur.distance = app.$vm.getDistance(Number(cur.dimension),Number(cur.longitude));
							return cur;
						});
					}else{
						this.list = this.list.concat(res.data.list.data.map(cur=>{
							cur.distance = app.$vm.getDistance(Number(cur.dimension),Number(cur.longitude));
							return cur;
						}));
					}
					if(res.data.list.last_page>this.page){
						this.moreFlag = true;
					}else{
						this.moreFlag = false;
					}
				})
			},
			//搜索
			searchBtn(){
				// alert(this.keyword)
				this.getList();
			},
			selectItem(index){
				this.current = index
			}
		}
	}
</script>

<style scoped lang="less">
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
.Select-merchant{
	background-color: #F3F3F3;
	min-height: 100vh;
	// overflow: auto;
	
	.merchantBox{
		padding-top: 128upx;
		.merchant_top{
			position: fixed;
			top: 0;
			width: 750upx;
			height: 128upx;
			padding: 32upx 24upx;
			background-color: #fff;
			z-index: 9999;
			box-sizing: border-box;
			.searchBox{
				// margin-bottom: 24upx;
			}
			.Navigation{
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 203upx;
				.NavigationItem{
					font-size: 28upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #333333;
					padding: 8upx 0;
					
				}
				.currentColor{
					color: #FFAC3F;
					border-bottom: 5upx solid #FFAC3F;
				}
			}
		}
		.merchantList{
			padding: 16upx 24upx;
			.ProductItem{
				width: 702upx;
				background: #FFFFFF;
				opacity: 1;
				border-radius: 20upx;
				padding: 24upx;
				margin-bottom: 16upx;
				.ItemTop{
					display: flex;
					// border-bottom: 2upx solid #F5F5F5;
					// padding-bottom: 16upx;
					.ProductImage{
						width: 144upx;
						height: 144upx;
						border-radius: 8upx;
						// background-color: #FFAC3F;
						margin-right: 24upx;
						background-position: center;
						background-size: cover;
						image{
							width: 100%;
							height: 100%;
							border-radius: 8upx;
						}
					}
					.ProductInfo{
						width: calc(100% - 168upx);
						.ProductNameBox{
							display: flex;
							align-items: center;
							justify-content: space-between;
							.ProductName{
								font-size: 24upx;
								font-family: Source Han Sans CN;
								font-weight: bold;
								color: #333333;
							}
							.sales-volume{
								font-size: 16upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #FF8255;
							}
						}
						.addressBox{
							display: flex;
							justify-content: space-between;
							align-items: center;
							margin-top: 16upx;
							.address{
								font-size: 16upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #999999;
							}
							.addressNum{
								font-size: 16upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #999999;
							}
						}
						.ranking{
							width: auto;
							// width: 130upx;
							// height: 28upx;
							background: #FFF3C8;
							opacity: 1;
							border-radius: 8upx;
							padding: 8upx;
							font-size: 12upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #683B00;
							margin-top: 12upx;
							display: inline-block;
						}
						.evaluateBox{
							display: flex;
							align-items: center;
							flex-wrap: wrap;
							margin-top: 16upx;
							.evaluateItem{
								// width: 100px;
								// height: 20px;
								background: #FFF5EA;
								opacity: 1;
								border-radius: 8upx;
								padding:4upx 8upx;
								font-size: 12upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #FFAC3F;
								margin-right: 16upx;
								margin-bottom: 16upx;
							}
						}
					}
				}
				.ItemBottom{
					display: flex;
					flex-wrap: wrap;
					align-items: center;
					padding-top: 16upx;
					.couponBox{
						display: flex;
						align-items: center;
						margin-right: 64upx;
						margin-bottom: 24upx;
						.couponIcon{
							width: 28upx;
							height: 28upx;
							background: #FFAC3F;
							opacity: 1;
							border-radius: 8upx;
							text-align: center;
							line-height: 28upx;
							font-size: 16upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #FFFFFF;
						}
						.couponPrice{
							font-size: 16upx;
							font-family: Source Han Sans CN;
							font-weight: 500;
							color: #FFAC3F;
							margin-left: 8upx;
						}
						.coupontext{
							font-size: 16upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
							margin-left: 8upx;
						}
					}
					.couponBox:nth-child(2n+2){
						margin-right: 0;
					}
				}
			}
		}
	}
}
</style>
